import { useAlwaysLogin } from "../../hook/useAlwaysLogin.ts";
import { useLoadSysConfig } from "../../hook/useLoadSysConfig.ts";
import { Spin } from "antd";
import { useConfig } from "../../hook/D8dConfigProvider.tsx";
import { ReactNode } from "react";

interface Props {
  children?: ReactNode;
}

// 系统配置加载器组件
const SysConfigLoader = ({ children }: Props) => {
  const { useLoad } = useConfig();
  const sysConfigLoaded = useLoadSysConfig();
  useLoad?.();

  if (sysConfigLoaded) return children;
  return (
    <div>
      <Spin/>
    </div>
  );
};

// 主加载器组件
const HeaderLayoutLoader = ({ children }: Props) => {
  const isLogin = useAlwaysLogin();

  if (!isLogin) {
    return (
      <div>
        <Spin/>
      </div>
    );
  }

  return <SysConfigLoader>{children}</SysConfigLoader>;
};

export default HeaderLayoutLoader; 